﻿/* Copyright (c) 2009 Jakub Müller
 * 
 * Permission is hereby granted, free of charge,
 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KompoziceMistoDedicnosti {
	/// <summary>
	/// Komponenta poskytující standardní položky pro ToolStrip.
	/// </summary>
	public partial class StandardToolStripItemsProvider : Component, IToolStripItemsProvider {
		public StandardToolStripItemsProvider() {
			InitializeComponent();

			this.Initialize();
		}

		public StandardToolStripItemsProvider( IContainer container ) {
			container.Add( this );

			InitializeComponent();

			this.Initialize();
		}

		private IList<ToolStripItem> toolStripItems;
		protected IList<ToolStripItem> ToolStripItems {
			get { return this.toolStripItems; }
		}
		private void Initialize() {
			/* Položky se kopírují do kolekce "ToolStripItems",
			 * protože při zobrazení položek se změní nadřízený
			 * položek a v objekt "standardToolStrip"
			 * nikdy více dané položky obsahovat nebude.
			 */
			this.toolStripItems = this.standardToolStrip.Items.OfType<ToolStripItem>().ToList();

			this.tbtnNew.Click += new EventHandler( tbtnNew_Click );
			this.tbtnOpen.Click += new EventHandler( tbtnOpen_Click );
			this.tbtnSave.Click += new EventHandler( tbtnSave_Click );
		}

		void tbtnSave_Click( object sender, EventArgs e ) {
			this.OnSaveClick( e );
		}

		void tbtnOpen_Click( object sender, EventArgs e ) {
			this.OnOpenClick( e );
		}

		void tbtnNew_Click( object sender, EventArgs e ) {
			this.OnNewClick( e );
		}


		#region IToolStripItemsProvider Members

		public IEnumerable<ToolStripItem> GetToolStripItems() {
			return this.ToolStripItems;
		}

		#endregion

		protected virtual void OnNewClick( EventArgs e ) {
			this.NewClick.Raise( this, e );
		}
		public event EventHandler NewClick;
		protected virtual void OnOpenClick( EventArgs e ) {
			this.OpenClick.Raise( this, e );
		}
		public event EventHandler OpenClick;
		protected virtual void OnSaveClick( EventArgs e ) {
			this.SaveClick.Raise( this, e );
		}
		public event EventHandler SaveClick;
	}
}
